package scaladuct.lists.scala

import scaladuct.Property
import collection.IterableLike

/**
 * <p>
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Dec 14, 2010
 * Time: 12:30:54 PM
 */

trait ListsManager extends scaladuct.lists.ListsManager {
  class Iter[E](scalaIterator: Iterator[E]) extends java.util.Iterator[E] {
    def remove = error("not supported")

    def next = scalaIterator.next

    def hasNext = scalaIterator.hasNext
  }

  final def listForProperty(property: Property[AnyRef]): Option[scaladuct.lists.ListForProperty[AnyRef]] = {
    scalaListForProperty(property) match {
      case Some(listForProp) => {
        Some(new scaladuct.lists.ListForProperty[AnyRef](listForProp.property, new java.lang.Iterable[AnyRef] {
          def iterator = new Iter[AnyRef](listForProp.content.iterator)
        }, listForProp.editable, listForProp.multiChoice))
      }
      case None => None
    }
  }

  def scalaListForProperty(property: Property[AnyRef]): Option[ListForProperty[AnyRef]]

}

class ListForProperty[A](val property: Property[A],
                         val content: Iterable[A],
                         val editable: Boolean,
                         val multiChoice: Boolean)